package system

import (
	"server/a0"

	"github.com/gofrs/uuid/v5"
	"github.com/shopspring/decimal"
)

type Login interface {
	GetUsername() string
	GetNickname() string
	GetUUID() uuid.UUID
	GetUserId() uint
	GetAuthorityId() uint
	GetUserInfo() any
}

var _ Login = new(SysUser)

// type SysUser struct {
// 	a0.A_MODEL
// 	UUID          uuid.UUID      `json:"uuid" gorm:"index;comment:用户UUID"`
// 	UserName      string         `json:"user_name" gorm:"index;comment:用户登录名"`
// 	Password      string         `json:"-"  gorm:"comment:用户登录密码"`
// 	NickName      string         `json:"nick_name" gorm:";comment:用户昵称"`
// 	Avatar        string         `json:"avatar" gorm:"comment:用户头像"`
// 	AuthorityId   uint           `json:"authorityId" gorm:"default:888;comment:用户角色ID"`
// 	Authority     SysAuthority   `json:"authority" gorm:"foreignKey:AuthorityId;references:AuthorityId;comment:用户角色"`
// 	Authorities   []SysAuthority `json:"authorities" gorm:"many2many:sys_user_authority;"`
// 	Mobile        string         `json:"mobile" gorm:"comment:用户手机号"`
// 	Email         string         `json:"email" gorm:"comment:用户邮箱"`
// 	Enable        int            `json:"enable" gorm:"default:1;comment:用户是否被冻结 1正常 2冻结"`
// 	OriginSetting a0.Smap `json:"origin_setting" form:"origin_setting" gorm:"type:text;default:null;comment:配置;"`
// 	OpenID        string         `json:"open_id" form:"openID"`
// 	S人员modelID    uint           `json:"员工id" gorm:"column:员工id;"`
// }

type SysUser struct {
	a0.A_MODEL
	UUID          uuid.UUID      `json:"uuid" gorm:"index;comment:用户UUID"`
	UserName      string         `json:"user_name" gorm:"index;comment:用户登录名"`
	Password      string         `json:"-"  gorm:"comment:用户登录密码"`
	NickName      string         `json:"nick_name" gorm:";comment:用户昵称"`
	Avatar        string         `json:"avatar" gorm:"comment:用户头像"`
	AuthorityId   uint           `json:"authorityId" gorm:"default:888;comment:用户角色ID"`
	Authority     SysAuthority   `json:"authority" gorm:"foreignKey:AuthorityId;references:AuthorityId;comment:用户角色"`
	Authorities   []SysAuthority `json:"authorities" gorm:"many2many:sys_user_authority;"`
	Mobile        string         `json:"mobile" gorm:"type:char(15);comment:用户手机号"`
	Email         string         `json:"email" gorm:"comment:用户邮箱"`
	Enable        int            `json:"enable" gorm:"default:1;comment:用户是否被冻结 1正常 2冻结"`
	OriginSetting a0.Smap        `json:"origin_setting" form:"origin_setting" gorm:"type:text;default:null;comment:配置;"`
	OpenID        string         `json:"open_id" form:"openID"`
	S人员modelID    uint           `json:"员工id" gorm:"column:员工id;"`
	RealName      string         `json:"real_name" gorm:"column:real_name;type:varchar(25);not null;default:'';comment:真实姓名"`
	Birthday      int            `json:"birthday" gorm:"column:birthday;type:int(11);not null;default:0;comment:生日"`
	CardId        string         `json:"card_id" gorm:"column:card_id;type:varchar(20);not null;default:'';comment:身份证号码"`
	Mark          string         `json:"mark" gorm:"column:mark;type:varchar(255);not null;default:'';comment:用户备注"`
	PartnerId     int            `json:"partner_id" gorm:"column:partner_id;type:int(11);not null;default:0;comment:合伙人id"`
	GroupId       int            `json:"group_id" gorm:"column:group_id;type:int(11);not null;default:0;comment:用户分组id"`

	AddTime            uint            `json:"add_time" gorm:"column:add_time;type:int(11) unsigned;not null;default:0;comment:添加时间"`
	AddIp              string          `json:"add_ip" gorm:"column:add_ip;type:varchar(16);not null;default:'';comment:添加ip"`
	LastTime           uint            `json:"last_time" gorm:"column:last_time;type:int(11) unsigned;not null;default:0;comment:最后一次登录时间"`
	LastIp             string          `json:"last_ip" gorm:"column:last_ip;type:varchar(16);not null;default:'';comment:最后一次登录ip"`
	NowMoney           decimal.Decimal `json:"now_money" gorm:"column:now_money;type:decimal(12,2) unsigned;not null;default:0.00;comment:用户余额"`
	BrokeragePrice     decimal.Decimal `json:"brokerage_price" gorm:"column:brokerage_price;type:decimal(12,2);not null;default:0.00;comment:佣金金额"`
	Integral           uint            `json:"integral" gorm:"column:integral;type:int(10) unsigned;not null;default:0;comment:用户剩余积分"`
	Exp                decimal.Decimal `json:"exp" gorm:"column:exp;type:decimal(12,2);not null;default:0.00;comment:会员经验"`
	SignNum            int             `json:"sign_num" gorm:"column:sign_num;type:int(11);not null;default:0;comment:连续签到天数"`
	SignRemind         int8            `json:"sign_remind" gorm:"column:sign_remind;type:tinyint(1);not null;default:0;comment:签到提醒状态"`
	Status             int8            `json:"status" gorm:"column:status;type:tinyint(1);not null;default:1;comment:1为正常，0为禁止"`
	Level              uint8           `json:"level" gorm:"column:level;type:tinyint(2) unsigned;not null;default:0;comment:等级"`
	AgentLevel         int             `json:"agent_level" gorm:"column:agent_level;type:int(10);not null;default:0;comment:分销等级"`
	SpreadOpen         int8            `json:"spread_open" gorm:"column:spread_open;type:tinyint(1);not null;default:1;comment:是否有推广资格"`
	SpreadUid          uint            `json:"spread_uid" gorm:"column:spread_uid;type:int(10) unsigned;not null;default:0;comment:推广员id;index:spreaduid"`
	SpreadTime         uint            `json:"spread_time" gorm:"column:spread_time;type:int(11) unsigned;not null;default:0;comment:推广员关联时间"`
	UserType           string          `json:"user_type" gorm:"column:user_type;type:varchar(32);not null;default:'';comment:用户类型"`
	IsPromoter         uint8           `json:"is_promoter" gorm:"column:is_promoter;type:tinyint(1) unsigned;not null;default:0;comment:是否为推广员;index:is_promoter"`
	PayCount           uint            `json:"pay_count" gorm:"column:pay_count;type:int(11) unsigned;not null;default:0;comment:用户购买次数"`
	SpreadCount        int             `json:"spread_count" gorm:"column:spread_count;type:int(11);not null;default:0;comment:下级人数"`
	CleanTime          int             `json:"clean_time" gorm:"column:clean_time;type:int(11);not null;default:0;comment:清理会员时间"`
	Addres             string          `json:"addres" gorm:"column:addres;type:varchar(255);not null;default:'';comment:详细地址"`
	Adminid            uint            `json:"adminid" gorm:"column:adminid;type:int(11) unsigned;not null;default:0;comment:管理员编号"`
	LoginType          string          `json:"login_type" gorm:"column:login_type;type:varchar(36);not null;default:'';comment:用户登陆类型，h5,wechat,routine"`
	RecordPhone        string          `json:"record_phone" gorm:"column:record_phone;type:varchar(11);not null;default:'0';comment:记录临时电话"`
	IsMoneyLevel       int8            `json:"is_money_level" gorm:"column:is_money_level;type:tinyint(1);not null;default:0;comment:会员来源  0: 购买商品升级   1：花钱购买的会员2: 会员卡领取"`
	IsEverLevel        int8            `json:"is_ever_level" gorm:"column:is_ever_level;type:tinyint(1);not null;default:0;comment:是否永久性会员  0: 非永久会员  1：永久会员"`
	OverdueTime        int64           `json:"overdue_time" gorm:"column:overdue_time;type:bigint(20);not null;default:0;comment:会员到期时间"`
	Uniqid             string          `json:"uniqid" gorm:"column:uniqid;type:varchar(32);not null;default:'';comment:用户唯一值"`
	DivisionName       string          `json:"division_name" gorm:"column:division_name;type:varchar(255);not null;default:'';comment:事业部/代理商名称"`
	DivisionType       int8            `json:"division_type" gorm:"column:division_type;type:tinyint(1);not null;default:0;comment:代理类型：0普通，1事业部，2代理，3员工"`
	DivisionStatus     int8            `json:"division_status" gorm:"column:division_status;type:tinyint(1);not null;default:0;comment:代理状态"`
	IsDivision         int8            `json:"is_division" gorm:"column:is_division;type:tinyint(1);not null;default:0;comment:事业部状态"`
	IsAgent            int8            `json:"is_agent" gorm:"column:is_agent;type:tinyint(1);not null;default:0;comment:代理状态"`
	IsStaff            int8            `json:"is_staff" gorm:"column:is_staff;type:tinyint(1);not null;default:0;comment:员工状态"`
	DivisionId         int             `json:"division_id" gorm:"column:division_id;type:int(11);not null;default:0;comment:事业部id"`
	AgentId            int             `json:"agent_id" gorm:"column:agent_id;type:int(11);not null;default:0;comment:代理商id"`
	StaffId            int             `json:"staff_id" gorm:"column:staff_id;type:int(11);not null;default:0;comment:员工id"`
	DivisionPercent    int             `json:"division_percent" gorm:"column:division_percent;type:int(11);not null;default:0;comment:分佣比例"`
	DivisionChangeTime int             `json:"division_change_time" gorm:"column:division_change_time;type:int(11);not null;default:0;comment:事业部/代理/员工修改时间"`
	DivisionEndTime    int             `json:"division_end_time" gorm:"column:division_end_time;type:int(11);not null;default:0;comment:事业部/代理/员工结束时间"`
	DivisionInvite     int             `json:"division_invite" gorm:"column:division_invite;type:int(11);not null;default:0;comment:代理商邀请码"`
	IsDel              int8            `json:"is_del" gorm:"column:is_del;type:tinyint(1);not null;default:0;comment:是否注销"`
}

func (SysUser) TableName() string {
	return "sys_users"
	// return "a_user"
}

func (s *SysUser) GetUsername() string {
	return s.UserName
}

func (s *SysUser) GetNickname() string {
	return s.NickName
}

func (s *SysUser) GetUUID() uuid.UUID {
	return s.UUID
}

func (s *SysUser) GetUserId() uint {
	return s.ID
}

func (s *SysUser) GetAuthorityId() uint {
	return s.AuthorityId
}

func (s *SysUser) GetUserInfo() any {
	return *s
}
